package com.totem.order.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.totem.order.model.TWalletJournal;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

@Mapper
public interface TWalletJournalMapper extends BaseMapper<TWalletJournal> {

    @Select("select sum(amount) amount, sum(charges) charges from t_wallet_journal twj where twj.journal_type='RECHARGE' and twj.journal_state='FINISHED'")
    Map<String, BigDecimal> sumRecharge();

    @Select("select sum(amount) amount, sum(charges) charges " +
            " from t_wallet_journal twj " +
            " where twj.journal_type='RECHARGE' and twj.journal_state='FINISHED'" +
            " and twj.update_time between #{start} and #{end}")
    Map<String, BigDecimal> sumTodayRecharge(@Param("start") Date start, @Param("end") Date end);

    @Select("select sum(amount) amount, sum(charges) charges from t_wallet_journal twj where twj.journal_type='WITHDRAW' and twj.journal_state='FINISHED'")
    Map<String, BigDecimal> sumWithdraw();

    @Select("select sum(amount) amount, sum(charges) charges " +
            " from t_wallet_journal twj " +
            " where twj.journal_type='WITHDRAW' and twj.journal_state='FINISHED'" +
            " and twj.update_time between #{start} and #{end}")
    Map<String, BigDecimal> sumTodayWithdraw(@Param("start") Date start, @Param("end") Date end);
}
